package com.cskaoyan.controller.promote;

import com.cskaoyan.bean.MallCoupon;
import com.cskaoyan.model.bo.promote.SimpleMallCoupon;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.promote_ad.BaseData;
import com.cskaoyan.service.promote.CouponService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 优惠券模块
 *
 * @author：23117
 * @date: 2021/11/30
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponController {
    @Autowired
    CouponService couponService;


    @RequiresPermissions("admin:coupon:list")
    @RequestMapping("list")
    public BaseRespVo list(){
        BaseData data = couponService.list();
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions("admin:coupon:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody SimpleMallCoupon simpleMallCoupon){
        MallCoupon vo = couponService.create(simpleMallCoupon);
        return BaseRespVo.ok(vo);
    }

    @RequiresPermissions("admin:coupon:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MallCoupon mallCoupon){
        boolean status = couponService.update(mallCoupon);

        if (status) return BaseRespVo.ok(mallCoupon);
        return BaseRespVo.fail("更新失败");
    }

    @RequiresPermissions("admin:coupon:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MallCoupon mallCoupon){
        boolean status = couponService.delete(mallCoupon);

        if (status) return BaseRespVo.ok();
        return BaseRespVo.fail("删除失败");
    }
    @RequestMapping("read")
    public BaseRespVo read(Integer id){

        MallCoupon data = couponService.read(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("listuser")
    public BaseRespVo listUser(Integer page,Integer limit,Integer couponId){

        BaseData data = couponService.listUser(page,limit,couponId);

        return BaseRespVo.ok(data);
    }

}


//@RequestMapping("update")
//@RequestMapping("delete")
//@RequestMapping("listuser")
